package hhb.game.zhualaoer.core;

import hhb.game.zhualaoer.core.dao.Card;
import hhb.game.zhualaoer.core.dao.PokerHand;
import hhb.game.zhualaoer.core.enums.Rank;
import hhb.game.zhualaoer.core.enums.Suit;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        // 测试各种牌型比较
        testThreeOfAKindA();
    }
    private static void testThreeOfAKindA() {
        PokerHand hand1 = new PokerHand(Arrays.asList(
                new Card(Suit.DIAMOND, Rank.SEVEN),
                new Card(Suit.HEART, Rank.EIGHT),
                new Card(Suit.DIAMOND, Rank.SIX)
        ));

        PokerHand hand2 = new PokerHand(Arrays.asList(
                new Card(Suit.HEART, Rank.ACE),
                new Card(Suit.SPADE, Rank.KING),
                new Card(Suit.DIAMOND, Rank.SEVEN)
        ));

        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println("比较结果: " + compareHands(hand1, hand2));
        System.out.println();
    }

    private static void testThreeOfAKind() {
        PokerHand hand1 = new PokerHand(Arrays.asList(
                new Card(Suit.SPADE, Rank.ACE),
                new Card(Suit.HEART, Rank.ACE),
                new Card(Suit.DIAMOND, Rank.ACE)
        ));

        PokerHand hand2 = new PokerHand(Arrays.asList(
                new Card(Suit.CLUB, Rank.KING),
                new Card(Suit.HEART, Rank.KING),
                new Card(Suit.DIAMOND, Rank.KING)
        ));

        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println("比较结果: " + compareHands(hand1, hand2));
        System.out.println();
    }

    private static void testStraightFlush() {
        PokerHand hand1 = new PokerHand(Arrays.asList(
                new Card(Suit.SPADE, Rank.ACE),
                new Card(Suit.SPADE, Rank.KING),
                new Card(Suit.SPADE, Rank.QUEEN)
        ));

        PokerHand hand2 = new PokerHand(Arrays.asList(
                new Card(Suit.HEART, Rank.KING),
                new Card(Suit.HEART, Rank.QUEEN),
                new Card(Suit.HEART, Rank.JACK)
        ));

        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println("比较结果: " + compareHands(hand1, hand2));
        System.out.println();
    }

    private static void testFlush() {
        PokerHand hand1 = new PokerHand(Arrays.asList(
                new Card(Suit.SPADE, Rank.ACE),
                new Card(Suit.SPADE, Rank.KING),
                new Card(Suit.SPADE, Rank.JACK)
        ));

        PokerHand hand2 = new PokerHand(Arrays.asList(
                new Card(Suit.SPADE, Rank.ACE),
                new Card(Suit.SPADE, Rank.KING),
                new Card(Suit.SPADE, Rank.QUEEN)
        ));

        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println("比较结果: " + compareHands(hand1, hand2));
        System.out.println();
    }

    private static void testPair() {
        PokerHand hand1 = new PokerHand(Arrays.asList(
                new Card(Suit.SPADE, Rank.ACE),
                new Card(Suit.HEART, Rank.ACE),
                new Card(Suit.DIAMOND, Rank.KING)
        ));

        PokerHand hand2 = new PokerHand(Arrays.asList(
                new Card(Suit.CLUB, Rank.ACE),
                new Card(Suit.DIAMOND, Rank.ACE),
                new Card(Suit.HEART, Rank.QUEEN)
        ));

        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println("比较结果: " + compareHands(hand1, hand2));
        System.out.println();
    }

    private static void testHighCard() {
        PokerHand hand1 = new PokerHand(Arrays.asList(
                new Card(Suit.SPADE, Rank.ACE),
                new Card(Suit.HEART, Rank.KING),
                new Card(Suit.DIAMOND, Rank.JACK)
        ));

        PokerHand hand2 = new PokerHand(Arrays.asList(
                new Card(Suit.CLUB, Rank.ACE),
                new Card(Suit.HEART, Rank.KING),
                new Card(Suit.DIAMOND, Rank.QUEEN)
        ));

        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println("比较结果: " + compareHands(hand1, hand2));
        System.out.println();
    }

    private static String compareHands(PokerHand hand1, PokerHand hand2) {
        int result = hand1.compareTo(hand2);
        if (result > 0) {
            return "第一手牌获胜";
        } else if (result < 0) {
            return "第二手牌获胜";
        } else {
            return "平局";
        }
    }
}    